package com.woniu.cq.medical.controller.component;

import com.woniu.cq.medical.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @BelongsProject: practice
 * @BelongsPackage: com.example.practice.controller.component
 * @Author: rofus
 * @CreateTime: 2020-09-03 19:22
 * @Description: 全局异常处理
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handleException(Exception e, HttpServletResponse response){
        log.warn("全局异常拦截",e);

        return Result.fail("SYS_ERROR","系统出错："+e.getMessage());
    }
}
